package com.xinhua.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinhua.dao.SsmpMapper;
import com.xinhua.domain.Ssmp;
import com.xinhua.service.IbookService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BookServiceImpl2 extends ServiceImpl<SsmpMapper, Ssmp> implements IbookService {
    @Autowired
    private SsmpMapper ssmpMapper;

    @Override
    public IPage<Ssmp> getPage(int currentPage, int pageSize) {
        IPage page = new Page(currentPage, pageSize);
        ssmpMapper.selectPage(page, null);
        return page;
    }

    @Override
    public IPage<Ssmp> getPage(int currentPage, int pageSize, Ssmp ssmp) {
        LambdaQueryWrapper<Ssmp> lqw = new LambdaQueryWrapper<Ssmp>();
        lqw.like(Strings.isNotEmpty(ssmp.getType()), Ssmp::getType, ssmp.getType());
        lqw.like(Strings.isNotEmpty(ssmp.getName()), Ssmp::getName, ssmp.getName());
        lqw.like(Strings.isNotEmpty(ssmp.getDescripton()), Ssmp::getDescripton, ssmp.getDescripton());
        IPage page = new Page(currentPage, pageSize);
        ssmpMapper.selectPage(page, lqw);
        return page;
    }

    @Override
    public boolean update(Ssmp ssmp) {
        return ssmpMapper.updateById(ssmp) > 0;
    }

//    @Override
//    public IPage<Ssmp> getPage(int currentPage, int pageSize, Ssmp ssmp) {
//        LambdaQueryWrapper<Ssmp> lqw = new LambdaQueryWrapper<Ssmp>();
//        lqw.like(Strings.isNotEmpty(ssmp.getType()), Ssmp::getType, ssmp.getType());
//        lqw.like(Strings.isNotEmpty(ssmp.getName()), Ssmp::getName, ssmp.getName());
//        lqw.like(Strings.isNotEmpty(ssmp.getDescripton()), Ssmp::getDescripton, ssmp.getDescripton());
//        IPage page = new Page(currentPage, pageSize);
//        ssmpMapper.selectPage(page, lqw);
//        return page;
//    }
}
